package com.link.base.core.basic.util.datax;

import java.util.ArrayList;
import java.util.List;

/**
 * 开盖扫码H5
 * @author 何启谦
 * @date 2019/4/26
 */
public class KaiGaiSaoMa {

    /**
     * 开盖扫码 - 扫码表字段映射
     *
     * @author liying
     * @date 2019/04/12
     */
    public static String qrCodeTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        // 临时表名称
        String tempTableName = "kgsm_merge_qrcode";
        // 正式表名称
        String targetTableName = "lnk_qrcode";
        // 填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();

        fieldList.add(new FieldMapping("'KaiGaiSaoMa'", "from_platform", "VARCHAR(100)"));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_accnt s1 where "
                + "s1.wx_open_id = t1.open_id and s1.ACCT_CHANNEL = 'wx0f55badcd4fe002c' limit 1)",
                "acct_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("qr_id", "qr_code", "VARCHAR(100)"));
        fieldList.add(new FieldMapping("(case t1.ext_no when null then 'out' when '' then 'out' else 'ext' end)",
                "qr_type", "VARCHAR(100)"));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_prod s1 where "
                + "s1.old_prod_code = t1.prod_code limit 1)", "prod_id", "VARCHAR(100)").setRequired(true).setUpdateFlag(false));

        fieldList.add(new FieldMapping("add_time", "scan_time", "DATETIME"));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_saleactivity s1 "
                + "where s1.from_platform = 'KaiGaiSaoMa' and s1.activity_type = 'ExScan' and s1.integration_id = t1.game_id limit 1)",
                "scene_id", "varchar(50)").setRequired(true));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName, fieldList, "from_platform");
    }

    /**
     * 开盖扫码 - 客户奖品字段映射
     *
     * @author liying
     * @date 2019/04/12
     */
    public static String couponsAccntTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        // 临时表名称
        String tempTableName = "kgsm_merge_inner_coupons_accnt";
        // 正式表名称
        String targetTableName = "lnk_inner_coupons_accnt";
        // 填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();

        fieldList.add(new FieldMapping("'KaiGaiSaoMa'", "from_platform", "VARCHAR(100)"));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_accnt s1 where "
                + "s1.wx_open_id = t1.open_id AND s1.ACCT_CHANNEL = 'wx0f55badcd4fe002c' limit 1)",
                "accnt_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_coupons s1 join linkcrm.lnk_saleactivity s2 "
                + "on s1.activity_id = s2.row_id where s1.integration_id = t1.prize_id and s2.from_platform = 'KaiGaiSaoMa' limit 1)",
                "coupons_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("num", "claimant_num", "INT(22)"));
        fieldList.add(new FieldMapping("time", "claim_time", "DATETIME"));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_saleactivity s1 "
                + "where s1.from_platform = 'KaiGaiSaoMa' and s1.activity_type = 'ExPrize' and s1.integration_id = t1.game_id limit 1)",
                "activity_id", "varchar(50)").setRequired(true));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName, fieldList, "from_platform");
    }

    /**
     * 开盖扫码 - 酒评字段映射
     *
     * @author liying
     * @date 2019/04/13
     */
    public static String wineReviewTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        // 临时表名称
        String tempTableName = "kgsm_merge_wine_review";
        // 正式表名称
        String targetTableName = "lnk_wine_review";
        // 填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();

        fieldList.add(new FieldMapping("'KaiGaiSaoMa'", "from_platform", "VARCHAR(100)"));
        fieldList.add(new FieldMapping("ext_no", "qr_code", "VARCHAR(100)"));
        fieldList.add(new FieldMapping("msg", "msg", "VARCHAR(1000)"));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_prod s1 where "
                + "s1.old_prod_code = t1.prod_code limit 1)", "prod_id", "VARCHAR(100)").setRequired(true).setUpdateFlag(false));

        fieldList.add(new FieldMapping("add_time", "review_time", "DATETIME"));
        fieldList.add(new FieldMapping("star", "star", "varchar(50)"));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName, fieldList, "from_platform");
    }
}
